<template>
  <div class="manager-container">
    <!--  头部  -->
    <div class="manager-header">
      <!-- <div class="manager-header-left">
        <img src="@/assets/logo.png" />
        <div class="title">企业人力资源管理系统</div>
      </div> -->

      <div class="manager-header-center">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: $route.path }">{{ $route.meta.name }}</el-breadcrumb-item>
        </el-breadcrumb>
      </div>

      <div class="manager-header-right">
        <el-dropdown>
          <div class="avatar">
            <arrow-down />
            <img :src="user.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
            <div class="text" >{{ user.username || '' }}</div>
          </div>
          <template #dropdown>
          <el-dropdown-menu>
            <!-- <el-dropdown-item @click.native="goToPerson">个人信息</el-dropdown-item> -->
            <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
        </el-dropdown>
      </div>
    </div>

    <!--  主体  -->
    <div class="manager-main">
      <!--  侧边栏  -->
      <div class="manager-main-left">
        <el-menu router style="border: none" :default-active="$route.path">

          <el-menu-item v-if="user.isBelong==1" index="/home/select">
            <el-icon><CollectionTag /></el-icon>
            <span slot="title">学生选题</span>
          </el-menu-item>

          <el-menu-item  v-if="user.isBelong==1" index="/home/topicInfo">
            <el-icon><Memo /></el-icon>
            <span slot="title">已选题目</span>
          </el-menu-item>

          <el-menu-item v-if="user.isBelong==0" index="/home/subject">
            <el-icon><House /></el-icon>
            <span slot="title">学生选题情况</span>
          </el-menu-item>

          <el-menu-item v-if="user.isBelong==0" index="/home/addTopic">
            <el-icon><DocumentAdd /></el-icon>
            <span slot="title">教师出题</span>
          </el-menu-item>

        </el-menu>
      </div>

      <!--  数据表格  -->
      <div class="manager-main-right">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Manager",
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem('user') || '{}'),
      keyPath: [],
    }
  },
  created() {
    let a = JSON.parse(sessionStorage.getItem('user') || '{}')
    console.log(a);
    if (!this.user) {
      this.$router.push('/')
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
      this.keyPath = [key];
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
      this.keyPath = [key];
    },
    homeClick() {
      this.menuActive = "";
      this.$refs.menu.close(this.KeyIndex);
    },
    updateUser() {
      this.user = JSON.parse(sessionStorage.getItem('user') || '{}')   // 重新获取下用户的最新信息
    },
    goToPerson() {
      if (this.user.role === 'ADMIN') {
        this.$router.push('/adminPerson')
      }
      if (this.user.role === 'USER') {
        this.$router.push('/employeePerson')
      }
    },
    logout() {
      sessionStorage.removeItem('user')
      sessionStorage.removeItem('token')
      this.$router.push('/')
    }
  }
}
</script>

<style scoped>
@import "@/assets/css/manager.css";
.text{
  color: #000000;
}
</style>